import java.util.Comparator;
import java.util.Iterator;


public class Congress
{
	private static int freeSeats 		= 0;
	private static int numberOfStates 	= 0;
	private static MaxPQ<State> p;
	private static In		in;
	
	public static void main(String[] args)
	{
		in = new In(args[0]);
		numberOfStates 	= Integer.parseInt(in.readLine());
		freeSeats		= Integer.parseInt(in.readLine());
		
		p = new MaxPQ(numberOfStates, new Comparator() {
			public int compare(Object obj1, Object obj2)
			{
				int pop1 = ((State)obj1).getPopD();
				int pop2 = ((State)obj2).getPopD();
				
				if(pop1 > pop2)			return 1;
				else if(pop1 < pop2)	return -1;
				else					return 0; 
			}
		});
		
		int i = 0;
		while(!in.isEmpty())
		{
			String name = in.readLine();
			int	pop		= Integer.parseInt(in.readLine());
			State state = new State(name, pop);
			p.insert(state);
			i++;
			freeSeats--;
		}
		
		while(freeSeats > 0)
		{
			State state = p.delMax();
			state.addSeat();
			p.insert(state);
			
			freeSeats--;
		}
		
		Iterator<State> it = p.iterator();
		while(it.hasNext())
		{
			State state = it.next();
			System.out.println(state.getName() + "\t\t" + state.getSeats());
		}
	}
}
